import Vue from 'vue'
import Vuex from 'vuex'
import createPersistedState from 'vuex-persistedstate'
Vue.use(Vuex)

export default new Vuex.Store({
  state: {
    token: "",
    user_id: "",
    list:"",
    list:[]
  },
  mutations: {
    add(state, token) {
      state.token = token
      state.user_id = token.user_id
      //  console.log(stete.user);
    },
    tui(state) {
      state.token = ""
    },
    getUser(state) {
      return state.user
    },
    addd(state,val){
      state.list=val
    }
      

  },
  actions: {},
  modules: {},
  getters:{
    total(state){
      console.log(state);
     var  sum=0
     state.list.forEach(item=>{
       sum+=item.num
     })
     return sum
    },
    totals(state){
     var  ssum=0
     state.list.forEach(item=>{
       ssum+=item.price*item.num
     })
     return ssum
    }
  },
  plugins: [createPersistedState()]
})